﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace AvansRS.Web.Util
{
    public class Password
    {
        [Required(ErrorMessage = "Wachtwoord is verplicht.")]       
        public string InitialPassword { get; set; }
        [Required(ErrorMessage = "Bevestig Wachtwoord is verplicht.")]       
        [CustomValidation(typeof(Password), "Validate")]
        public string ConfirmPassword { get; set; }

        public bool IsEmpty()
        {
            return String.IsNullOrEmpty(InitialPassword)
                && String.IsNullOrEmpty(ConfirmPassword);
        }

        public static bool Validate(string confirmPassword, ValidationContext context, out ValidationResult result)
        {
            result = null;
            Password password = (Password)context.ObjectInstance;

            if (password.InitialPassword != confirmPassword)
            {
                result = new ValidationResult("Wachtwoord moet overeen komen met het Bevestigde wachtwoord!");
                return false;
            }            
            
            return true;
        }
    }   
}
